# -*- coding:utf-8 -*-
"""
顾客信息管理Model
"""
from django.db import models
from apps.app_setting.models import SysParam

# 客人信息表
class CustomerInfo(models.Model):
    """
    顾客基础信息表
    """
    customer_id = models.AutoField(primary_key=True)
    customer_name = models.CharField(
        max_length=20, db_index=True, verbose_name='姓名')
    customer_gender = models.ForeignKey(
        'app_setting.SysParam',
        on_delete=models.PROTECT,
        related_name='customerinfo_customer_gender', verbose_name='性别')
    customer_birthday = models.DateField(
        null=True, blank=True, verbose_name='生日')
    customer_joindate = models.DateField(
        blank=True, verbose_name='加入时间')
    introducer_customer = models.CharField(
        max_length=18, blank=True, verbose_name='推荐人',
        help_text="填写由哪个客人推荐")
    introducer_mark = models.BooleanField(default=False, verbose_name='推荐标识')
    # 客人类型
    customer_type = models.CharField(
        max_length=20, blank=True, verbose_name='类型')
    # 客人职业
    customer_vocation = models.CharField(
        max_length=20, blank=True, verbose_name='职业')
    # 客人手机
    customer_mobile = models.CharField(
        max_length=15, blank=True, verbose_name='手机')
    customer_tel = models.CharField(
        max_length=15, null=True, blank=True, verbose_name='电话')
    customer_qq = models.CharField(
        max_length=20, null=True, blank=True, verbose_name='QQ号码')
    customer_email = models.EmailField(
        max_length=50, blank=True, verbose_name='邮箱')
    customer_weixin = models.CharField(
        max_length=50, blank=True, verbose_name='微信')
    # 客人状态
    customer_state = models.BooleanField(default=True, verbose_name='状态')
    # 开户店名
    customer_store_name = models.CharField(
        max_length=50, blank=True, verbose_name='开卡店')
    # 备注
    customer_memo = models.TextField(
        blank=True, verbose_name='备注')
    # 客人来源
    customer_source = models.ForeignKey(
        'app_setting.SysParam',
        on_delete=models.PROTECT,
        related_name='customerinfo_customer_source', verbose_name='客源'
    )
    # 买卡备注
    buy_card_mark = models.BooleanField(
        default=False, verbose_name='是否购卡')
    # 创建日期
    create_date = models.DateField(
        verbose_name='创建日期', auto_now_add=True)

    # 自定义表名
    class Meta:
        verbose_name = '客人基本资料'
        verbose_name_plural = '客人基本资料'
        db_table = 'customers_customer_info'
        ordering = ['customer_id']

    # def __str__(self):
    #     return self.customer_name
    def to_json(self):
        """
        定义转换为json数据
        """
        print('customer_source', self.customer_source.param_name)

        json_data = {
            'customer_id': self.customer_id,
            'customer_name': self.customer_name,
            'customer_birthday': self.customer_birthday,
            'customer_source': self.customer_source.param_name,
            'customer_gender': self.customer_gender.param_name,
            'customer_qq': self.customer_qq,
            'customer_email': self.customer_email,
            'customer_joindate': self.customer_joindate,
            'customer_memo': self.customer_memo,
            'customer_mobile': self.customer_mobile
        }
        return json_data
